package com.ieheima.demo;

import java.io.*;

public class ObjectClass03 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student s1 = new Student("张三", 23);
        Student s2 = new Student("李四", 24);
        Student s3 = new Student("王五", 25);
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream("day13\\e.txt"));
        oos.writeObject(s1);
        oos.writeObject(s2);
        oos.writeObject(s3);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(
                new FileInputStream("day13\\e.txt"));
        while (true) {
            try {
                //读取Object对对象时会报错误，这里需要捕获错误
                Object o = ois.readObject();
                System.out.println(o);
            } catch (IOException e) {
                break;
            }
        }
        ois.close();
    }
}
